<div id="body" class="none" >
	<script type="text/javascript">
		loadeJs('./js/ImgBox.js', 'ImgBoxPage', function() {
			console.log('./js/ImgBox.js loaded');
		});
		</script>
	<script>
		var rentalContent = "Тут будет текст о условия продажи вещей\n";

		var hireContent = new Array();
		<?php 
		$desc->printJS("selling_page_terms", "rentalContent");
		if(isset($_GET['description'])){
			print "var currentPages = 'description';\n";
		} else {
			print "var currentPages = 'selling';\n";
		}			
		?>
		function editDesc() {
			query("admin&action=get_desc&desc=selling_page_terms&uid=" + UserData.uid, function(data) {
				HtmlBox.open(data.content, function() {	
					window.location.reload()
				});
			});
		}
		
		if(UserData.isAdmin){
			rentalContent += "</br> <a class='enable' href='javascript:' onclick='editDesc()'>Edit</a>";
		}
		
		function getSellingContent(){
			return getSellingContent(null);
		}
		
		function getSellingContent(callback) {
			query("product_items&action=sell_items", function(data){
				if(typeof data == 'string'){
					hireContent = JSON.parse(data);
				} else {
					hireContent = data;
				}
				if(callback!=null) {
					callback(hireContent);
				}
				return hireContent;
				//hireContent = jQuery.parseJSON(unescape(data));
			});
		}
		function openImgPopup(selector){
			cosole.log(selector)
		}
		function openTab(page){
			if(page=='description'){
				$('#body_box').html(rentalContent);
			} else {
				$('#body_box').html('');
				if($('#img_box_con') == null || $('#img_box_con').length==0){
					$('#body_box').append('<div id="img_box_con">');
				}
				if(hireContent.length==0) {
					getSellingContent(function(hireContent){
						createSellingContent()
					});
				} else {
					createSellingContent();
				}
				
			}
		}
		
		function createSellingContent(){
			for(var i = 0; i < hireContent.length; i++){
				(function f() {
					var itemIndex = i;
					var img_id = addImgBox(hireContent[itemIndex]);
					$('#'+img_id).click(function(){
						console.log("$('#"+img_id+"').click" + itemIndex);
						console.log(hireContent[itemIndex].id);
						ImgBox.open2(hireContent[itemIndex].id, hireContent, UserData.isAdmin);
					});
				})();
			}
			var adminItem = {};
			adminItem.img = "http://img.playground.ru/images/2/3/green-plus-sign-hi.png";
			if(UserData.isAdmin){
				var btnId = addBtn(adminItem);
				console.log(btnId);
				$('#' + btnId).click(function(){
					query("admin&action=add_new_item&uid=" + UserData.uid, function(data){
						if(typeof data == 'string'){
							data = JSON.parse(data);
						}
						HtmlBox.open(data.content);
					});	
					
				});
			}
		}
		$(function(){
			var unSelectableElName = '.items_list';
			unselectElement(unSelectableElName);
			openTab(currentPages);
			
		});
	</script>
	<div id="left_content" class="text_content" >
		<div class="items_list">
			<div class="item top" onclick="openTab('description');">условия продажи</div>
			<div class="item bottom" onclick="openTab('selling');">костюмы на продажу</div>	
		</div>
	</div>
	<div id="body_box" class="text_content" > 		
	</div>
	<div id="body_info" class="text_content" > 
		<table>
			<tr>
				<td><span id="login_button" onclick="VK.Auth.login(authInfo);"></span></td>
				<td><span id="vk_like"></span></td>
			</tr>
		</table>
	</div>
	
</div>
